/**
 * zmn员工模块-员工角色列表
 * 文件命名格式：zmn.模块名称.表名称.功能.js
 * @author heguanghua
 * @since 2020/05/11 13:38
 */
layui.define(['index', 'form', 'table', 'zmnApp', 'laypage'], function (exports) {
    let $ = layui.$;
    let form = layui.form;
    let layer = layui.layer;
    let table = layui.table;
    let laypage = layui.laypage;
    let zmnApp = layui.zmnApp;

    table.init('zmn-table', {
        toolbar: "#zmn-table-tool",
        page: true,
        limit: json.pageSize,
        height: 'full-235'
    });
    laypage.render(zmnPage.laypageOptions(json));

    // 取消/添加（批量）
    table.on("toolbar(zmn-table)", function (obj) {
        if(obj.event == "cancel") {
            let ids = appUtil.layTabldIds(obj, ['roleId'], 'staffId');
            if(ids.length === 0){ return layer.alert("请选择要取消对此员工已授权的角色"); }
            layui.layer.confirm('确认取消授权吗？', function() {
                zmnPage.ajaxSimple(zmnApp.SYS_BASE_URL +"/staff/role/modify/cancel.action", { ids: ids.join(",")}, 1000);
            });
        } else if(obj.event == "add") {
            layer.open({
                type: 2,
                area: ['1000px', '600px'],
                fixed: false,
                maxmin: true,
                title: '选择角色',
                content: zmnApp.SYS_BASE_URL +'/common/role/list.action?multi=2&callbackUrl=/staff/role/modify/add.action&keyId=' + json.staffId
            });
        }
    });

    layer.ready(function(){
        if(json.status){
            $("#status").val(json.status);
            form.render();
        }
    });

    //对外暴露的接口
    exports('staff_role_list', {});
});
